<?php

namespace backend\models;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "decree_type".
 *
 * @property int $id
 * @property string $title
 * @property string|null $short_description
 */
class DecreeType extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'decree_type';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['title'], 'required'],
            [['title'], 'string', 'max' => 255],
            [['short_description'], 'string', 'max' => 512],
            [['title'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Название',
            'short_description' => 'Краткое описание',
        ];
    }

    public static function decreeTypeList()
    {
        return ArrayHelper::map(
            self::find()->orderBy('title')->asArray()->all(), 
            'id', 
            'title'
        );
    }
}
